package com.chb.system.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.system.annotation.OperLogAnnotation;
import com.chb.system.service.DictDataService;
import com.chb.system.vo.DictDataVo;
import com.hos.entity.sys.DictData;
import com.hos.entity.sys.DictType;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/8 17:29
 * @description:
 * @modified By:
 * @version:
 */
@RestController
@RequestMapping("system/api/dictData")
@Api(value = "字典相关接口")
public class ApiDictDataController {

    @Resource
    private DictDataService dictDataService;

    @GetMapping("/{dictType}")
    @ApiOperation(value = "获取字典数据")
    public Result<List<DictData>> getDictData(@PathVariable String dictType) {
        return new Result<>(200, "获取字典数据成功", dictDataService.getDictData(dictType));
    }

    @PostMapping("findDictDataByCond")
    @ApiOperation(value = "条件查询字典数据信息")
    public Result<Page<DictData>> findDictDataByCond(@RequestBody DictDataVo dictDataVo) {
        return new Result<>(200, "查询成功", dictDataService.findDictDataByCond(dictDataVo));
    }

    @DeleteMapping("deleteDictDataByIds/{ids}")
    @ApiOperation(value = "根据字典数据ID永久删除字典数据信息")
    @OperLogAnnotation(business_type = "系统业务-删除字典数据", operator_type = 1)
    public Result<Integer> deleteDictDataByIds(@PathVariable List<Long> ids) {
        return new Result<>(200, "删除成功", dictDataService.deleteDictDataByIds(ids));
    }

    @PostMapping("updateDictDate")
    @ApiOperation(value = "修改字典数据")
    @OperLogAnnotation(business_type = "系统业务-修改字典数据", operator_type = 1)
    public Result updateDictDate(@RequestBody DictData dictData) {
        return new Result<>(200, "修改成功", dictDataService.updateDictDate(dictData));
    }

    @PostMapping("getDictDataById/{dectDataId}")
    @ApiOperation(value = "根据字典数据ID查询到一个字典数据")
    public Result<DictType> getDictDataById(@PathVariable Long dectDataId) {
        return new Result<>(200, "查询成功", dictDataService.getDictDataById(dectDataId));
    }

    @PostMapping("addDictData")
    @ApiOperation(value = "添加字典数据")
    @OperLogAnnotation(business_type = "系统业务-增加字典信息", operator_type = 1)
    public Result<Integer> addDictData(DictData dictData) {
        return new Result<>(200, "添加成功", dictDataService.addDictData(dictData));
    }
}